package gh625simpleviewer;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

public class OneDay implements Comparable {

    Integer Year;
    Integer Month;
    Integer Day;
    Integer Duration_msec;
    Integer Distance;
    Integer Calories;
    List<Track> DayTracks = new ArrayList<Track>();

    @Override
    public String toString() {
        String year = Year.toString();
        String month = Month.toString();
        if (month.length() < 2) {
            month = "0" + month;
        }
        String day = Day.toString();
        if (day.length() < 2) {
            day = "0" + day;
        }
        return "Date: " + year + "-" + month + "-" + day;
    }

    @Override
    public int compareTo(Object o) {
        Calendar c0 = new GregorianCalendar(Year, Month - 1, Day);
        OneDay no = (OneDay) o;
        Calendar c1 = new GregorianCalendar(no.Year, no.Month - 1, no.Day);
        return c0.compareTo(c1);
    }

    public String getDurationString() {
        Integer Duration_h, Duration_m, Duration_s;
        Duration_h = (Duration_msec / 360000);
        Duration_m = (Duration_msec - Duration_h * 360000) / 6000;
        Duration_s = (Duration_msec - Duration_h * 360000 - Duration_m * 6000) / 100;
        String hour = Duration_h.toString();
        if (hour.length() < 2) {
            hour = "0" + hour;
        }
        String min = Duration_m.toString();
        if (min.length() < 2) {
            min = "0" + min;
        }
        String sec = Duration_s.toString();
        if (sec.length() < 2) {
            sec = "0" + sec;
        }
        return hour + ":" + min + ":" + sec;
    }
}
